<?php
namespace admin\action;

use herosphp\http\HttpRequest;
use herosphp\utils\AjaxResult;
use herosphp\bean\Beans;

/**--tmpl-use--**/

class OperationLogAction extends CommonAction {
	protected $order = 'addtime DESC';

	public function C_start()
	{
		parent::C_start();	
		/**--tmpl-starttodo--**/
	}

	/**--tmpl-vars--**/

	protected $serviceBean="admin.operationLog.service";


	/**--tmpl-construct--**/

	/**--tmpl-method--**/

	/**-- actionAdd --**/
	public function add(HttpRequest $request) {
	
		parent::add($request);
	
		/**--tmpl-addtodo--**/
	
		$this->assign("title", "添加操作日志");
		$this->assign('bread', array('网站设置','操作日志',$this->getTemplateVar('title')));
		$this->assign('breadUrl', array('javascript:;',url('admin/operationLog/index'),'javascript:;'));
	
	}
	
	/**-- actionEdit --**/
	public function edit(HttpRequest $request) {
	
		/**--tmpl-editbefore--**/
		parent::edit($request);
		/**--tmpl-editafter--**/
	
		$this->assign("title", "编辑操作日志");
		$this->assign('bread', array('网站设置','操作日志',$this->getTemplateVar('title')));
		$this->assign('breadUrl', array('javascript:;',url('admin/operationLog/index'),'javascript:;'));
	}
	
	/**-- actionIndex --**/
	public function index(HttpRequest $request) {

		$this->page = $request->getParameter('page', 'intval');
		if ( $this->page <=0 ) {
			$this->page = 1;
		}
		$conditions = array();
		$this->assign('_table','操作日志');
		$s_opname = $request->getParameter('s_opname');
		$this->assign('s_opname',$s_opname);
		if($s_opname !== '' && $s_opname!== NULL)$conditions['opname'] = '%'.$s_opname.'%';
		$s_opkey = $request->getParameter('s_opkey');
		$this->assign('s_opkey',$s_opkey);
		if($s_opkey !== '' && $s_opkey!== NULL)$conditions['opkey'] = '%'.$s_opkey.'%';
		$s_remark = $request->getParameter('s_remark');
		$this->assign('s_remark',$s_remark);
		if($s_remark !== '' && $s_remark!== NULL)$conditions['remark'] = '%'.$s_remark.'%';
		$s_addtime = $request->getParameter('s_addtime');
		$this->assign('s_addtime',$s_addtime);
		if($s_addtime !== '' && $s_addtime!== NULL)$conditions['addtime'] = '%'.$s_addtime.'%';
		$s_manager_id = $request->getParameter('s_manager_id');
		$this->assign('s_manager_id',$s_manager_id);
		if($s_manager_id !== '' && $s_manager_id!== NULL)$conditions['manager_id'] = $s_manager_id;
		$s_app_id = $request->getParameter('s_app_id');
		$this->assign('s_app_id',$s_app_id);
		if($s_app_id !== '' && $s_app_id!== NULL)$conditions['app_id'] = '%'.$s_app_id.'%';
		$this->assign('_filter',array('opname','opkey','remark','addtime','manager_id','app_id'));
		$this->assign('_header',array('操作名称','操作','操作说明','添加时间','添加人','appid'));
		$this->setConditions($conditions);
	
		$pagesize = $request->getParameter('pagesize') ? $request->getParameter('pagesize') : $this->getPagesize();
		$order = $request->getParameter('order') ? $request->getParameter('order') : $this->getOrder();
		$order = str_replace('+' , " ",$order);
		$this->setPagesize($pagesize);
		$this->setOrder($order);
		$this->assign('order',$order);
		$this->assign('pagesize',$pagesize);
		//parent::index($request);

		$service = Beans::get($this->getServiceBean());
		$total = $service->count($this->getConditions());
		$items = $service->getItems($this->getConditions(), $this->getFields(), $this->getOrder(),
			array($this->getPage(), $this->getPagesize()), $this->getGroup(), $this->getHaving());
		$this->generatePageMenu($total);
		$this->assign('page',$this->page);
		$this->assign('items',$items);

		$this->assign("title", "操作日志");
		$this->assign('bread', array('网站设置',$this->getTemplateVar('title')));
		$this->assign('breadUrl', array('javascript:;','javascript:;'));
		$this->setView(strtolower($request->getAction()) . '/index');

	}
	
	/**-- doAddMethod --**/
	public function do_add(HttpRequest $request)
	{
		$data = $request->getParameter('data');
	
		/**--tmpl-todo--**/
		$request->addParameter('data',$data);
		parent::do_add($request);	
	}
	
	/**-- doEditMethod --**/
	public function do_edit(HttpRequest $request){
		$data = $request->getParameter('data');
	
		/**--tmpl-todo--**/
		$request->addParameter('data',$data);
		parent::do_edit($request);	
	}
	
	

}
